<template>
<div class="layout">
  <head :hasleft="true">
    <div slot="right" class="rightBox" @click="rightClick">
      <text class="leftIcon iconfont">&#xe600;</text>
    </div>
    <div slot="center" class="inputbox" @click="searchClick()">
      <text class="searchIcon iconfont">&#xe62a;</text>
      <text class="tipsinput">noteBook</text>
    </div>
  </head>
  <div class="pageContent">
    <scroller class="scroller" @loadmore="onloadmore" loadmoreoffset="200" :show-scrollbar="false">
      <refresh class="refresh" @refresh="onrefresh" :display="refreshing ? 'show' : 'hide'">
        <loading-indicator class="indicator"></loading-indicator>
      </refresh>
      <div class="cicleContent">
        <div class="silderBox">
          <slider class="slider" interval="3000" auto-play="false">
            <div
              class="frame"
              v-for="(img,index) in bannerList"
              :key="index"
              @click="toBanner(img)"
            >
              <image class="image" resize="cover" :src="img.image_url" />
            </div>
            <indicator class="indicators"></indicator>
          </slider>
        </div>
        <div class="bgcf">
          <div class="recommend">
            <div class="retitle">
              <text class="fz30">Recommended</text>
              <!-- <text class="iconfont reIcon">view more &#xe6a1;</text> -->
            </div>
            <div class="recontent">
              <div class="reitem" v-for="(item,index) in secondList" :key="index">
                <image
                  class="goodsImg"
                  :src="item.thumb"
                  @click="gonext('root:app/goods/goods2.js',{id:item.id,type:item.type})"
                />
                <div class="contentBox">
                  <text class="goodsTitle2">{{item.title}}</text>
                  <div class="priceInfo">
                    <div class="secondPrice">
                      <text class="symbol">AU$</text>
                      <text class="money">{{item.price}}</text>
                      <!-- <text class="reduce">80%</text> -->
                      <!-- <text class="shopType">NEW</text> -->
                    </div>
                    <div class="leftInfo">
                      <!-- <text class="iconfont shopIcon">&#xe64c;</text>
                      <text class="iconfont shopIcon">&#xe634;</text>
                      <text class="iconfont shopIcon">&#xe607;</text>-->
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="loadingbox" v-if="hasMore">
        <image
          class="loading"
          src="https://img.alicdn.com/tfs/TB1CWnby7yWBuNjy0FpXXassXXa-32-32.gif"
        />
      </div>
      <text class="loadingbox" v-if="!hasMore">No more</text>
    </scroller>
  </div>
</div>
</template>
<script>
import asCore from "../../mixin/core";
import { get_goods_list, get_banner_list } from "../../mixin/ajax.js";
export default {
  data() {
    return {
      users_id: "",
      page: 1,
      hasMore: true,
      refreshing: false,
      shopTotal: 0,
      bannerList: [], //banner图
      tabSection: [
        {
          img: "root:img/nav1.png",
          title: "Phone"
        },
        {
          img: "root:img/nav2.png",
          title: "Electronics"
        },
        {
          img: "root:img/nav3.png",
          title: "Books"
        },
        {
          img: "root:img/nav4.png",
          title: "Appliances"
        },
        {
          img: "root:img/nav5.png",
          title: "Clothes"
        },
        {
          img: "root:img/nav6.png",
          title: "Cosmetics"
        },
        {
          img: "root:img/nav7.png",
          title: "Furniture"
        },
        {
          img: "root:img/nav8.png",
          title: "Baby"
        }
      ],
      countdown: {}, //倒计时
      secondList: [],
      shopList: []
    };
  },
  created() {
    let that = this;
    // that.loadData();
    that.loadPromotion();
    asCore.getBsessionid(userId => {
      this.loadData(userId);
    });
  },
  methods: {
    toBanner(item) {
      if (item.type) {
        if (item.type == "1") {
          this.push("root:app/goods/goods.js", { id: item.link_url });
        } else {
          this.push("root:app/app.js", item);
        }
      }
    },
    onrefresh(event) {
      var s = this;
      s.refreshing = true;
      let that = this;
      that.loadData(that.users_id);
      setTimeout(() => {
        s.refreshing = false;
      }, 1000);
    },
    onloadmore() {
      if (this.hasMore) {
        this.page++;
        this.getGoodList();
      }
    },
    loadData(users_id) {
      let that = this;
      that.page = 1;
      if (users_id) {
        that.users_id = users_id;
      }
      get_banner_list({ type: 2 }, (res, flag) => {
        if (flag) {
          if (res.code == "200") {
            that.bannerList = res.data;
          } else {
            that.toast(res.message);
          }
        }
      });
      this.getGoodList();
    },
    getGoodList() {
      let that = this;
      // 推荐商品
      get_goods_list(
        {
          users_id: "",
          keywords: "",
          categoryid: "",
          type: "1,2",
          status: "1",
          page: this.page
        },
        (res, flag) => {
          if (flag) {
            if (res.code == "200") {
              that.shopTotal == res.total;
              if (this.page == 1) {
                that.secondList = res.data.list;
              } else {
                that.secondList = that.secondList.concat(res.data.list);
              }
              if (res.data.list.length == 0) {
                that.hasMore = false;
              }
            } else {
              that.toast(res.message);
            }
          }
        }
      );
    },
    gonext(url, parmar) {
      this.push(url, parmar);
    },

    searchClick(item) {
      this.push("root:app/goods/searchGoods.js", { types: 2 });
    },

    rightClick() {
      this.push("root:app/msg/msg.js");
    }, //定时器
    Timer() {
      let that = this;
      setInterval(() => {
        if (that.countdown) {
          if (
            !(
              that.countdown.h == 0 &&
              that.countdown.m == 0 &&
              that.countdown.s == 0
            )
          ) {
            if (that.countdown.s > 0) {
              that.countdown.s--;
              that.countdown.s =
                that.countdown.s < 10
                  ? "0" + that.countdown.s
                  : that.countdown.s;
            } else if (that.countdown.m > 0) {
              that.countdown.m--;
              that.countdown.m =
                that.countdown.m < 10
                  ? "0" + that.countdown.m
                  : that.countdown.m;
              that.countdown.s = 59;
            } else if (that.countdown.h > 0) {
              that.countdown.h--;
              that.countdown.h =
                that.countdown.h < 10
                  ? "0" + that.countdown.h
                  : that.countdown.h;
              that.countdown.m = 59;
              that.countdown.s = 59;
            }
          }
        }
      }, 1000);
    },
    loadPromotion() {
      let cutTime = new Date();
      let yy = cutTime.getFullYear(),
        mm = cutTime.getMonth() + 1,
        dd = cutTime.getDate();
      let h1 = cutTime.getHours();
      let tmpcountdown = yy + "/" + mm + "/" + dd + " " + h1 + ":59:59";
      let h = "00",
        m = "00",
        s = "00";
      let currentTime = new Date();
      let cutoffTime = new Date(tmpcountdown);
      if (!(currentTime >= cutoffTime)) {
        let countTime = parseInt(
          (cutoffTime.getTime() - currentTime.getTime()) / 1000
        );
        h = parseInt(countTime / 3600);
        m = parseInt((countTime % 3600) / 60);
        s = countTime % 60;
        h = h < 10 ? "0" + h : h;
        m = m < 10 ? "0" + m : m;
        s = s < 10 ? "0" + s : s;
      }
      this.countdown = {
        h: h,
        m: m,
        s: s
      };
      this.Timer();
    }
  }
};
</script>

<style scoped lang="less">
.iconfont {
  font-family: iconfont;
}
.rightBox {
  justify-content: center;
  align-items: center;
  flex-direction: row;
  // background-color: #fff;
  flex: 1;
  &:active {
    background-color: #222222;
  }
}
.layout {
  background-color: #f2f2f2;
  flex: 1;
}
.leftIcon {
  color: #ffffff;
  font-size: 40px;
}
.loadingbox {
  align-items: center;
  padding: 20px;
  height: 80px;
  margin-bottom: 20px;
  text-align: center;
  color: #999999;
}

.loading {
  height: 40px;
  width: 40px;
}

.pageContent {
  flex: 1;
  position: relative;
}

.scroller {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
}

.header {
  height: 400px;
  /* padding-top: 45px; */
  justify-content: flex-start;
  align-items: center;
  background-color: #303030;
}

.refresh {
  width: 750px;
  -ms-flex-align: center;
  -webkit-align-items: center;
  -webkit-box-align: center;
  align-items: center;
}

.indicator {
  margin-top: 30px;
  margin-bottom: 20px;
  height: 70px;
  width: 70px;
  color: #ce2020;
}
.indicators {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 60px;
  item-color: #ddd;
  item-selected-color: #ba8833;
}
.inputbox {
  background-color: #fff;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  border-radius: 50px;
  height: 76px;
  padding: 0 40px;
  margin: 0 20px;
  /* margin-left: 32px; */
}

.searchIcon {
  color: #666;
  margin-right: 15px;
  font-size: 30px;
}
.noteBook {
  font-size: 28px;
  font-family: PingFangSC-Regular, PingFangSC;
  font-weight: 400;
  color: rgba(153, 153, 153, 1);
  line-height: 40px;
}

.cicle {
  background-color: #f2f2f2;
  border-top-left-radius: 600px;
  border-bottom-right-radius: 600px;
  width: 750px;
  height: 750px;
  transform: rotate(45deg);
  margin-top: 60px;
}

.tips {
  color: #666;
  font-size: 22px;
}
.tipsinput {
  font-size: 28px;
  font-family: PingFangSC-Regular, PingFangSC;
  font-weight: 400;
  color: rgba(153, 153, 153, 1);
  line-height: 40px;
}

.img {
  width: 200px;
  height: 200px;
  margin-top: -100px;
}

.text {
  color: black;
  margin-top: 30px;
  font-size: 70px;
  font-weight: bold;
  margin-bottom: 50px;
}

.image {
  width: 750px;
  height: 290px;
  // border-top-left-radius: 20px;
  // border-top-right-radius: 20px;
  // border-bottom-right-radius: 20px;
  // border-bottom-left-radius: 20px;
  overflow: hidden;
  background-color: #fff;
}

.silderBox {
  width: 750px;
  height: 290px;
  // margin-left: 30px;
  // border-top-left-radius: 20px;
  // border-top-right-radius: 20px;
  // border-bottom-right-radius: 20px;
  // border-bottom-left-radius: 20px;
  overflow: hidden;
}

.slider {
  flex: 1;
  position: relative;
}

.frame {
  width: 750px;
  height: 290px;
  position: relative;
  // border-top-left-radius: 20px;
  // border-top-right-radius: 20px;
  // border-bottom-right-radius: 20px;
  // border-bottom-left-radius: 20px;
  overflow: hidden;
}

.bgcf {
  background-color: #f2f2f2;
}

.tabSection {
  width: 690px;
  height: 350px;
  background-color: #ffffff;
  border-radius: 10px;
  margin-left: 30px;
  margin-top: 40px;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;

  align-items: center;
  padding-top: 30px;
}

.tabItem {
  width: 172.5px;
  justify-content: center;
  align-items: center;
  margin-top: 10px;
  margin-bottom: 10px;
  &:active {
    background-color: #f2f2f2;
  }
}

.tabImg {
  width: 90px;
  height: 90px;
}

.subSection {
  width: 690px;
  margin-left: 30px;
  margin-top: 20px;
  flex-direction: row;
  justify-content: space-between;
}

.leftSub {
  width: 330px;
  height: 230px;
  border-radius: 10px;
  background-color: #fff;
}

.subTop {
  flex-direction: row;
  padding: 20px 30px;
  justify-content: space-between;
  align-items: flex-end;
}

.topTitle {
  color: #bb8732;
  font-size: 38px;
}

.limitImg {
  width: 305px;
  margin-left: 8px;
  height: 140px;
}

.timeOut {
  flex-direction: row;
  align-items: center;
}

.timeNum {
  width: 30px;
  height: 30px;
  background-color: #bb8732;
  color: #fff;
  border-radius: 5px;
  text-align: center;
  line-height: 30px;
  font-size: 20px;
}

.timesyb {
  color: #bb8732;
  margin: 0 2px;
}

.rightSub {
  width: 330px;
  height: 230px;
  border-radius: 10px;
  background-color: #fff;
  padding: 20px 25px;
  justify-content: space-between;
  align-items: center;
}
.titleBox {
  justify-content: flex-start;
}

.rightTitle {
  font-size: 40px;
  color: #bb8732;
  height: 56px;
  line-height: 56px;
  margin-bottom: 8px;
  width: 280px;
}

.rightContent {
  font-size: 28px;
  line-height: 34px;
  color: #666;
  width: 280px;
  lines: 2;
  text-overflow: ellipsis;
}

.rightBtn {
  width: 166px;
  height: 45px;
  line-height: 45px;
  text-align: center;
  color: #fff;
  font-size: 28px;
  background-color: rgba(186, 136, 51, 1);
  border-radius: 23px;
}

.luckImg {
  width: 686px;
  height: 138px;
  margin-left: 32px;
  margin-top: 50px;
  margin-bottom: 50px;
}

.secondHand {
  width: 750px;
  background-color: #ffffff;
  height: 440px;
}

.secondTitle {
  height: 100px;
  flex-direction: row;
  justify-content: space-between;
  padding: 20px;
  align-items: center;
  &:active {
    background-color: #f9f9f9;
  }
}

.secondItem {
  width: 220px;
}

.secondPrice {
  flex-direction: row;
  align-items: center;
}

.mr5 {
  margin-right: 5px;
}

.titleName {
  font-size: 34px;
  color: #c09345;
}

.secondIcon {
  font-size: 32px;
  color: #666666;
}

.secondContent {
  width: 750px;
  height: 340px;
  flex-direction: row;
}

.listItem {
  padding: 20px;
  width: 240px;
  height: 340px;
}

.SecondImg {
  width: 200px;
  height: 200px;
}

.recommend {
  width: 690px;
  margin-left: 30px;
  margin-top: 30px;
}

.retitle {
  width: 690px;
  padding: 20px 0;
  font-size: 30px;
  justify-content: space-between;
  align-items: center;
  flex-direction: row;
}

.fz30 {
  font-size: 34px;
}

.reIcon {
  color: #666666;
  font-size: 28px;
}

.recontent {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-between;
  padding-bottom: 30px;
}

.reitem {
  height: 516px;
  margin-top: 10px;
  margin-bottom: 10px;
  background-color: #fff;
  border-radius: 10px;
  /* justify-content: space-between; */
}

.goodsImg {
  width: 336px;
  height: 336px;
}

.contentBox {
  width: 336px;
  padding: 0 20px;
}

.goodsTitle {
  font-size: 20px;
  height: 56px;
  line-height: 28px;
  margin-top: 12px;
  color: #1e1e1e;
  text-overflow: ellipsis;
  lines: 2;
}

.goodsTitle2 {
  font-size: 26px;
  height: 74px;
  line-height: 37px;
  margin-top: 16px;
  color: #1e1e1e;
  text-overflow: ellipsis;
  lines: 2;
}

.priceInfo {
  margin-top: 20px;
  flex-direction: row;
  justify-content: space-between;
}

.leftInfo {
  flex-direction: row;
  align-items: flex-end;
}

.symbol {
  color: red;
  // margin-bottom: 5px;
  font-size: 20px;
  line-height: 20px;
}

.money {
  color: red;
  font-size: 32px;
  line-height: 32px;
  font-weight: bold;
  margin-right: 5px;
}

.reduce {
  color: red;
  margin-right: 5px;
}

.shopType {
  color: red;
}

.shopIcon {
  font-size: 32px;
  margin-left: 10px;
}

.user {
  flex-direction: row;
  margin-top: 15px;
}

.avator {
  width: 40px;
  height: 40px;
  border-radius: 40px;
  margin-top: 15px;
}

.userInfo {
  flex: 1;
  padding-left: 15px;
}

.userName {
  font-size: 32px;
  color: #333;
}

.c666 {
  color: #666;
  margin-top: 5px;
}
</style>
